package com.example.reagent_management.di;

import android.content.Context;

import com.example.reagent_management.room.dao.HistoryDao;
import com.example.reagent_management.room.dao.MessageDao;
import com.example.reagent_management.room.dao.StoreDao;
import com.example.reagent_management.room.dao.ReagentInDao;
import com.example.reagent_management.room.database.AppDataBase;

import javax.inject.Singleton;

import androidx.annotation.NonNull;
import dagger.Module;
import dagger.Provides;
import dagger.hilt.InstallIn;
import dagger.hilt.android.qualifiers.ApplicationContext;
import dagger.hilt.components.SingletonComponent;

//数据模块 提供注入项
//注入项 一般都写到di包下
//其他地使用的时候使用@Inject 注入
@InstallIn(SingletonComponent.class)
@Module
public final class DataBaseModule {

    @Singleton
    @Provides
    public final AppDataBase provideAppDatabase(@ApplicationContext @NonNull Context context){
        return AppDataBase.Companion.getInstance(context);
    }

    @Provides
    public final StoreDao provideReagentDao(@NonNull AppDataBase appDataBase){
        return appDataBase.storeDao();
    }

    @Provides
    public final ReagentInDao provideReagentInDao(@NonNull AppDataBase appDataBase){
        return appDataBase.reagentInDao();
    }
    @Provides
    public final HistoryDao provideHistoryDao(@NonNull AppDataBase appDataBase){
        return appDataBase.historyDao();
    }

    @Provides
    public final MessageDao provideMessageDao(@NonNull AppDataBase appDataBase){
        return appDataBase.messageDao();
    }
}
